import { markersPoint } from '@/config';

export function addMarkers(map: any) {
  const TMap = (window as any).TMap;
  if (!TMap) throw new Error('TMap 未注入');

  const geometries = markersPoint.map((m) => ({ id: m.id, styleId: 'marker', position: new TMap.LatLng(...m.position) }));
  const instance = new TMap.MultiMarker({
    id: 'marker-layer',
    map,
    styles: { marker: new TMap.MarkerStyle({ width: 20, height: 28, enableRelativeScale: true }) },
    geometries,
  });

  instance.on('click', (evt: any) => {
    console.log('markerID:', evt.geometry.id);
    console.log('当前marker位置：', evt.geometry.position.toString());
  });

  map.on('zoom_changed', () => {
    const currentZoom = map.getZoom();
    instance.setVisible(currentZoom >= 16.5);
  });

  return instance;
}

export default { addMarkers };
